#include "main_header.h"
int use_remove(dirStack_t *stack, int netfd, MYSQL *db, char *username) {
  train_t train;
  printf("执行删除文件命令\n");
  // 获取要删除文件的名字
  recvn(netfd, &train.length, sizeof(train.length));
  recvn(netfd, train.data, train.length);
  char *filename = strdup(train.data);         // 存储文件名
  int primaryKey = stack->idArr[stack->index]; // 获取栈顶指针元素
  // 逻辑删除数据库中的文件
  char sql[1024] = {0};
  snprintf(sql, sizeof(sql),
           "update file set is_deleted=1 where username='%s' and filename='%s' "
           "",
           username, filename);
  int ret = execDB(sql, db);
  ERROR_CHECK(ret, -1, "delete error");
  printf("删除文件成功\n");
  free(filename);
  return 0;
}
